<template>
  <div class="comment-reply">
    <van-nav-bar :title="comment.reply_count + '条回复'">
      <van-icon slot="left" name="cross" @click="$emit('close')" />
    </van-nav-bar>
    <comment-item :commentInfo="comment" />

    <van-cell title="所有回复" />
    <comment-list type="c" :source="comment.com_id" :list="commentList" />
    <!-- 底栏 -->
    <div class="article-bottom">
      <van-button
        class="comment-btn"
        plain
        round
        size="small"
        type="primry"
        @click="isPostShow = true"
        >写评论</van-button
      >
    </div>

    <!-- 评论评论的弹出窗 -->
    <van-popup v-model="isPostShow" position="bottom">
      <comment-post
        :target="comment.com_id"
        :articleId="articleId"
        @post-success="onPostSuccess"
      />
    </van-popup>
  </div>
</template>

<script>
import CommentItem from './comment-item'
import CommentList from './comment-list'
import CommentPost from './comment-post'
export default {
  components: {
    CommentItem,
    CommentList,
    CommentPost
  },
  props: {
    comment: {
      type: Object,
      required: true
    },
    articleId: {
      type: [Number, String, Object],
      required: true
    }
  },
  data() {
    return {
      isPostShow: false,
      commentList: []
    }
  },
  methods: {
    onPostSuccess(comment) {
      // 发布评论成功后
      // 将新的评论放到评论列表头部
      this.commentList.unshift(comment)
      // 关闭评论窗口
      this.isPostShow = false
      // 评论数量加 1
      this.comment.reply_count++
    }
  }
}
</script>

<style lang="less" scoped>
.comment-reply {
  .article-bottom {
    box-sizing: border-box;
    border-top: 1px solid #cccccc;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 40px;
    background-color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;

    .comment-btn {
      width: 240px;
      height: 28px;
      border: 1px solid #eeeeee;
      font-size: 15px;
      line-height: 23px;
      color: #a7a7a7;
    }
  }
}
</style>
